package cn.itqiqi.student_system_java.service.impl;

import cn.itqiqi.student_system_java.mapper.StudentAllMapper;
import cn.itqiqi.student_system_java.pojo.StuAllVo;
import cn.itqiqi.student_system_java.pojo.StudentAll;
import cn.itqiqi.student_system_java.service.StuAllService;
import cn.itqiqi.student_system_java.utils.ResultUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description
 * @date 2022-06-19 10:47
 */

@Service
public class StuAllServiceImpl extends ServiceImpl<StudentAllMapper, StudentAll> implements StuAllService  {

    @Autowired()
    private StudentAllMapper studentAllMapper;
    @Autowired
    private ResultUtils resultUtils;

    private final StuAllVo stuAllVo = new StuAllVo();

    @Override
    public String getStuAll(Long pageNum, Long pageSize) {
        Page<StudentAll> studentAllPage = new Page<>(pageNum, pageSize);
        List<StudentAll> stuAll = studentAllMapper.getStuAll(studentAllPage);
        long total = studentAllPage.getTotal();
        stuAllVo.setTotal(total);
        stuAllVo.setStudentAllList(stuAll);
        return resultUtils.success(stuAllVo);
    }

    @Override
    public String getStuAllByName(Long pageNum, Long pageSize, String sname) {
        Page<StudentAll> studentAllPage = new Page<>(pageNum, pageSize);
        List<StudentAll> stuAllByName = studentAllMapper.getStuAllByName(studentAllPage,sname);
        stuAllVo.setTotal(studentAllPage.getTotal());
        stuAllVo.setStudentAllList(stuAllByName);
        return resultUtils.success(stuAllVo);
    }

    @Override
    public String getStuAllBySax(Long pageNum, Long pageSize, String sax) {
        Page<StudentAll> studentAllPage = new Page<>(pageNum, pageSize);
        List<StudentAll> stuAllBySax= studentAllMapper.getStuAllBySax(studentAllPage,sax);
        stuAllVo.setTotal(studentAllPage.getTotal());
        stuAllVo.setStudentAllList(stuAllBySax);
        return resultUtils.success(stuAllVo);
    }

    @Override
    public String getStuAllByClassId(Long pageNum, Long pageSize, String classId) {
        Page<StudentAll> studentAllPage = new Page<>(pageNum, pageSize);
        List<StudentAll> stuAllByClassId = studentAllMapper.getStuAllByClassId(studentAllPage,classId);
        stuAllVo.setTotal(studentAllPage.getTotal());
        stuAllVo.setStudentAllList(stuAllByClassId);
        return resultUtils.success(stuAllVo);
    }


}
